#pragma once

#include <string>

#include "util/pool/pool.h"

namespace hawking {
namespace indexlib {

class AttributeConvertor {
public:
    AttributeConvertor(util::ColumnType column_type) : column_type_(column_type) {}
    virtual ~AttributeConvertor() = default;

    std::string_view Encode(const util::FieldValue* value_addr, Pool* pool) {
        return InnerEncode_(value_addr, pool);
    }

    void Decode(uint8_t* data_addr, util::FieldValue* value) {
        InnerDecode_(data_addr, value);
    }

protected:
    virtual std::string_view InnerEncode_(
        const util::FieldValue* value_addr, Pool* pool) = 0;
    virtual void InnerDecode_(const uint8_t* data_addr, util::FieldValue* value) = 0;

    char* Allocate_(Pool* pool, size_t size) {
        return (char*)pool->Allocate(size);
    }

    util::ColumnType column_type_;
};

}
}